#include <iostream>
#include <unordered_map>

using namespace std;

string word = "";

unordered_map<string, int> numbers = {
    {"zero", 0},
    {"one", 1},
    {"two", 2},
    {"three", 3},
    {"four", 4},
    {"five", 5},
    {"six", 6},
    {"seven", 7},
    {"eight", 8},
    {"nine", 9}
};

bool is_prime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i < n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int nearest_prime(int n) {
    if (is_prime(n)) {
        return n;
    }

    int lower = n;
    int upper = n;

    while (true) {
        if (is_prime(lower)) {
            return lower;
        }
        if (is_prime(upper)) {
            return upper;
        }
        lower--;
        upper++;
    }
}

int main() {
    bool right = true;
    
    string a, b, c;
    cin >> a >> b >> c;

    if (numbers.find(a) != numbers.end()) {
        word += to_string(numbers[a]);
    } else if (right) {
        right = false;
        cout << "Wrong input" << endl;
    }
    if (numbers.find(b) != numbers.end() && right) {
        word += to_string(numbers[b]);
    } else if (right) {
        right = false;
        cout << "Wrong input" << endl;
    }
    if (numbers.find(c) != numbers.end() && right) {
        word += to_string(numbers[c]);
    } else if (right) {
        right = false;
        cout << "Wrong input" << endl;
    }

    if (word.length() == 3) {
        cout << nearest_prime(stoi(word)) << endl;
    }

    return 0;
}
